package ciyuanwutuobang.Core;

import ciyuanwutuobang.Core.Config;
import ciyuanwutuobang.MainClass;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.io.File;

/**
 * @author 150149
 */
public class Command implements CommandExecutor {

    private MainClass mainClass;

    public Command(MainClass MainClass) {
        this.mainClass = MainClass;
    }

    @Override
    public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
        if ("cace".equalsIgnoreCase(cmd.getName())) {
            if (!sender.isOp() && !sender.equals(Bukkit.getConsoleSender())) {
                sender.sendMessage("Unkonwn command. Type \"/help\" for help.");
                return true;
            }
            if (args.length >= 1) {
                if ("reload".equals(args[0])) {
                    mainClass.reloadConfig();
                    mainClass.config = new Config(mainClass.getConfig(),mainClass);
                    mainClass.kickCountManager = new KickCountManager();
                    mainClass.kickCountManager.load();
                    sender.sendMessage("§8[ §c次元反变速 §8]§7配置文件重置成功");
                    return true;
                } else if ("test".equals(args[0])) {
                    if (args.length==1) {
                        MainClass.testPlayer="";
                        sender.sendMessage("§8[ §c次元反变速 §8]§7测试模式已关闭");
                        return true;
                    } else if (args.length==2) {
                        MainClass.testPlayer=args[1];
                        sender.sendMessage("§8[ §c次元反变速 §8]§7测试模式已开启，对象：§a" + MainClass.testPlayer);
                        return true;
                    }
                }
            }
            sender.sendMessage("§7§m---------------------§8[ §c次元反变速 §8]§7§m---------------------");
            sender.sendMessage("  ");
            sender.sendMessage("§7输入/cace test [ID] 监测某人速度");
            sender.sendMessage("§7输入/cace reload 重载配置文件");
            sender.sendMessage("  ");
            sender.sendMessage("§7§m---------------------§8[ §c次元反变速 §8]§7§m---------------------");
        }
        return true;
    }

}
